//filename: ppsadapter.h

#ifndef __PPSADAPTER_H_
#define __PPSADAPTER_H_
#include <errno.h>
#include <unistd.h>
#include "ipscopetbl.h"


#define PPS_MAX_ID_STR_LEN 16
#define PPS_MAX_DMA_NUM 16
#define PPS_MAX_PPC_NUM 200
#define PPS_MAX_IPSCOPE_NUM 200
#define PPS_MAX_RULER_NUM 256
#define PPS_MAX_DMADEV_NUM 30
#define PPS_MAX_LBE_NUM 10
#define PROTOCOL_GLOBE -1       //for debug
#define PROTOCOL_BT 0
#define PROTOCOL_EMULE 1
#define PROTOCOL_HTTP 2
#define PROTOCOL_EMULE_CRYPT 3
#define PROTOCOL_HTTP_CAS 4
#define PROTOCOL_XUNLEI 5
#define PROTOCOL_BT_HTTP 6
#define PROTOCOL_PUSH 7
#define PROTOCOL_RADIUS 8
#define PROTOCOL_MEDIA_CAS 9
#define PROTOCOL_BLACK 10
#define EMULE_DATAREQ_LENGTH 46

#define PROTOCOL_WEB_STAT 11
#define PROTOCOL_DNS_LEAD 12
#define PROTOCOL_PPSTREAM 13
#define PROTOCOL_NCSS_CAS 14
#define PROTOCOL_PPLIVE   15

#define PPS_PATH_MAX 256
#define PPCACHE_CONFIG_FILE_NAME "sysconfig.xml"
#define PPS_CONFIG_FILE_NAME "pps_config.xml"
#define PPS_FILT_FILE_NAME "pps_filt.xml"

#define RET_OK 0
#define RET_DELETE -2
typedef int (* FILTFUNC)(u_char *buf,int len,struct filtitem* pitem);
typedef int (* SESSFUNC)(struct session_node *,u_char *buf,int len,int direct);
/*======================================================*/
/*		About Global Variable			*/
/*======================================================*/
int cfg_write_cli_port(u_short port);
int cfg_read_cli_port(void);
int cfg_read_id();

int cfg_read_port();
int cfg_read_keepalive();

void set_conf_dir(char *path);
const char *get_conf_dir();

/*======================================================*/
/*		About Global Variable			*/
/*======================================================*/
void gbl_init(void);
void gbl_destroy(void);
pthread_rwlock_t* gbl_get_rwlock(void);
char* gbl_get_id(void);
int		gbl_get_send_sock(void);
const struct ipscopetable* 	gbl_get_ipscope_tbl(void);
struct ipscopetable* 	gbl_get_ipscope_all_tbl(void);
int gbl_get_network_card_type(void);
int cfg_read_network_card_type();

/*======================================================*/
/*    	About initialization of raw socket		*/
/*======================================================*/
int pps_init_raw_sock(void);
void pps_destroy_raw_sock(void);

int pps_set_id(const char* id);
int pps_get_id(char* id);

int get_check_stamp();
void set_check_stamp(int val);

int pps_set_port(int port);
int pps_get_port();
int init_udp_socket();
int get_udp_socket();

int cfg_read_DMA();
int pps_get_DMA(char *buf);
int pps_get_direct(char *dev);

int cfg_read_regular_debug();
int cfg_read_regular_info();

/*======================================================*/
/*		       About module client pool    			*/
/*======================================================*/
int pps_set_clientpool_redirect(int val);
int pps_get_clientpool_redirect();
int cfg_read_clientpool_redirect();

/*======================================================*/
/*	 About Host Range configuration			*/
/*======================================================*/
int cfg_read_ipscope(void);

void	pps_init_ipscope_tbl(void);
void	pps_init_ipscope_all_tbl(void);
int		pps_export_ipscope_tbl(struct ipscope* tbl, int nmax);
void	pps_clear_ipscope_tbl(void);
void	pps_clear_ipscope_all_tbl(void);

int	pps_add_ipscope(u_int32_t start, u_int32_t end,int flag);
int pps_unite_add_ipscope_table(const ipscope_table * table1, ipscope_table * table2, int flag);

int pps_get_status(char *buf);

/*======================================================*/
/*	           Other functions			*/
/*======================================================*/
bool pps_check_cfg_file(void);

/*======================================================*/
/*           About  debug                            */
/*======================================================*/
#define DEBUG_LEVEL_MAX 5
void pps_dbg_print(int level,int nodule,char *fmt,...);
int gbl_get_debuglevel(void);
int cfg_read_debug_level();
int pps_set_debug_level(int flag);
int pps_get_debug_level();
int gbl_get_globe_debug(void);
int cfg_read_globe_debug();
int pps_set_globe_debug(int flag);
int pps_get_globe_debug();


int pps_get_regular_num();


#endif
